package com.mls.fivedistrict.server.impl;

import com.mls.fivedistrict.common.ServiceResponse;
import com.mls.fivedistrict.dao.ExcelMapper;
import com.mls.fivedistrict.dao.PropertyMapper;
import com.mls.fivedistrict.dao.RecordMapper;
import com.mls.fivedistrict.pojo.*;
import com.mls.fivedistrict.server.ExcelService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by nanji on 2018/3/16.
 */
@Service("excelService")
public class ExcelServiceImpl implements ExcelService {
    @Resource(name = "excelMapper")
    private ExcelMapper excelMapper;
    @Resource(name = "recordMapper")
    private RecordMapper recordMapper;
    @Resource(name = "propertyMapper")
    private PropertyMapper propertyMapper;


    @Transactional
    @Override
    public ServiceResponse batchInsert(List<RecordForExcel> recordList) {
        int row = excelMapper.batchInsertSelective(recordList);
        if (row <= 0) {
            return ServiceResponse.createErrorResponse("插入错误");
        }
        row = excelMapper.batchUpdateProperty(recordList);
        if (row <= 0) {
            return ServiceResponse.createErrorResponse("插入错误");
        }
        return ServiceResponse.createSuccessResponse();
    }
}
